home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John L. Noland)
- Newsgroups: comp.lang.c
- Subject: Re: #include "" for large programs.
- Date: 12 Apr 1996 19:42:51 GMT
- Organization: Uno mas por favor
- Message-ID: <4kmbnr$89@newshost.cyberramp.net>
- References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
- NNTP-Posting-Host: ramp3-16.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan>, cdiaz@eng.usf.edu says...
- >
- > I've been writing short two part programs using the #include "filename"
- >preprocessor.
- > I call one file main.c and the other part2.c, for which there is a
- >prototype header file part2.h.
- > All works well when I compile the programs, except when part2.h has
- >#define constants (I've been advised by my professor to use #define for
- >constants over 'const type var_name'). My compiler returns a fatal error
- >reporting that the symbol in the #define is not defined.
- > For example if #define EQUAL 0 is part of part2.h, I'm told that the
- >symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
- >told that I've defined EQUAL TWICE, once in part2.h and again within
- >main. The book we're using in class is not helping at all in this subject,
- >and I cannot figure out why everything else is recognized, except #define
- >constants. Can anyone here help? If the answer to this is in the FAQ, just
- >tell me where to download it from. Thanks!
-
- Where are your header files located? It could be that the compiler
- isn't finding them. Usually you do something like this:
-
- #include <part2.h>
-
- which tells the compiler to look in the usual place for the
- file. I don't know what compiler you're using, but most have a
- place to put in the path to the include files. If your header
- is located in a different directory than this you need to do
- this:
-
- #include "part2.h"
-
- this tells it to look in the current working directory. You
- could put the explicit path like this:
-
- #include "c:/student/diaz/part2.h"
-
- Also in your header files you could do the following:
-
- #ifndef PART2_H
- #define PART2_H
-
- .....
-
- #endif
-
- This will prevent a header from being included twice.
-
- -John
-
-